<?
 include("../header.php");
 include("../lib/config.php");
 $nik	= $HTTP_GET_VARS['nik'];
 $show	= $HTTP_GET_VARS['show'];
 $nomor	= $HTTP_GET_VARS['nomor'];
 //$nama	= $HTTP_GET_VARS['nama'];
?>
<script type="text/javascript">
	function hapus(Cat,NIK,No)
	{
		var ok = confirm("Apakah Anda yakin menghapus data tersebut ?");
		if(ok == true)
		{
			window.location.href="delete.php?cat="+ Cat +"&nik="+ NIK +"&no="+No+"";
		}
		else
		{
		}
	}
	
	function ValidateInput(){
		if(document.FI.periode.value==""){
			alert("Maaf, Periode tahun harus dipilih ...");
			document.FI.periode.focus();
			return false;
		}
		
		document.FI.submit();
	}
	
	function show_popupL(page)
	{
		child = open
		(
			"../form/list_plafon.php?nik="+page+"",
			"",
			"scrollbars,width=900,height=400,left=150,top=150"
		);
	}
</script>
<?
if($show == "historical"){
	 // untuk hak akses
	$spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='medical'",$conn);
	$rpar = mssql_fetch_array($spar);	

?>
<table width="100%">
 <tr>
  <td class="line_bottom">&nbsp;&nbsp;<b>DATA PENGAJUAN PENGOBATAN</b> | <a href="<?=$PHP_SELF?>?show=setup_medical&amp;nik=<?=$nik?>">DATA PLAFON PENGOBATAN KARYAWAN</a></td>
 </tr>
</table>
<table width="100%">
 <tr>
  <td>
  <!---->
  <table width="100%">
  <?
  	$sNama = mssql_query("SELECT * FROM Karyawan WHERE NIK='$nik'",$conn);
	$rNama = mssql_fetch_array($sNama);
  ?>
   <tr> 
    <td width="120">NIK</td>
	<td><input type="text" name="nik" value="<?=$rNama[NIK]?>"  readonly=""/></td>
    <td rowspan="2" valign="middle">
     <table border="0" cellpadding="2" cellspacing="1" bgcolor="#F0EFFC" style="border:solid 1px #CCCCCC; text-decoration:blink;" width="100%" align="center">
      <tr>
       <td><b>Sisa Plafon Rawat Jalan Anda pada periode ini (<?
       if(!empty($HTTP_GET_VARS['filter'])){
	   		$per = $HTTP_GET_VARS['filter'];
	   }
	   else{
	   		$per = date("Y");
	   }
	   echo"$per";
	   ?>):</b></td>
      </tr>
      <tr>
       <td align="center" style="font-size:12px; font-weight:bold;">
       <?
	   	// get jumlah pengobatan yang telah disetujui
		$sRJ = mssql_query("SELECT SUM(jml_disetujui) tot_setuju FROM MedicalRestitusiDetail WHERE Periode='".$per."' AND NIK='$nik' AND mata_anggaran IN ('811101','811103','811105','811199') AND status='A'");
		$rRJ = mssql_fetch_array($sRJ);
		// get plafon pada periode yang dipilih
		$spRJ= mssql_query("SELECT PlafonRawatJalan FROM MedicalSetupAwal WHERE Periode='$per' AND NIK='$nik'");
		$rpRJ= mssql_fetch_array($spRJ);
		// sisa rawat jalan
		echo "Rp.".number_format($rpRJ[PlafonRawatJalan]-$rRJ['tot_setuju']);
	   ?>
       </td>
      </tr>
     </table>
    </td>
   </tr>
   <tr> 
    <td>Nama</td>
	<td><input type="text" name="nama" value="<?=$rNama[Nama]?>" size="50" readonly="" /></td>
   </tr>
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#CCCCCC" /></td>
 </tr>
 <tr>
  <td>
   <table width="100%" border="0" >
    <tr>
     <td width="40%" valign="top">
     <table>
      <tr>
       <td>
       <table>
       <form name="" action="<?=$PHP_SELF?>?show=historical" method="get">
        <tr>
         <td><b>Filter Data</b> &raquo; Periode: </td>
         <td><select name="filter">
         <option value="">--semua--</option>
         <?
          // get periode dari plafon
		  $splaf = mssql_query("SELECT periode FROM MedicalSetupAwal WHERE NIK='$nik' GROUP BY periode",$conn);
		  while($rplaf = mssql_fetch_array($splaf)){
		  	echo"<option value='$rplaf[0]'";
			if($HTTP_GET_VARS['filter'] == $rplaf[0]){
				echo" selected";
			}
			echo">$rplaf[0]</option>";
		  }
		 ?>
       </select> <input type="submit" value="Go!" class="button" /><input type="hidden" name="show" value="historical" /><input type="hidden" name="nik" value="<?=$nik?>"  />
       	 </td>
        </tr>
       </form>
       </table>
       </td>
      </tr>
     </table>
     </td>
     <td valign="middle">
   <table border="0" align="right">
   <form name="FI" action="../form/frm_emp_medical.php" method="get">
   	<tr>
	 <td><b><u><a href="Javascript:show_popupL('<?=$nik?>');">Lihat Sisa Plafon</a></u></b> | <b>Tambah Restitusi</b> &raquo; Pilih Periode:</td>
	 <td>
	  <select name="periode">
	   <?
		// get data periode from setup medical
		$sPeriode = mssql_query("SELECT periode FROM VSetupMedical WHERE NIK='$nik' GROUP BY Periode ORDER BY Periode DESC",$conn);
		while($rPeriode = mssql_fetch_array($sPeriode)){
			echo"<option value='$rPeriode[periode]'";
			if($rPeriode[periode] == date("Y")){
				echo" selected";
			}
			echo">$rPeriode[periode]</option>";
		}
	   ?>
	  </select>
	 </td>
	 <td>
	 <input type="hidden" value="<?=$nik?>" name="nik" />
     <input type="hidden" name="pengajuan" value="yes">
	 <input type="button" value="Tambah" class="button" onclick="Javascript:ValidateInput()" /></td>
	</tr>
   </form>
   </table>
   </td>
   </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td>
  <fieldset><legend>Daftar Historical Restitusi (yang sudah diajukan)</legend>
   <table>
    <tr class="headlist">
	 <td width="30">No.</td>
	 <td width="100">No. Restitusi</td>
	 <td width="75">Tgl. Restitusi</td>
	 <td width="75">Periode</td>
     <td>Jenis</td>
     <td>Total Yang Diajukan</td>
     <td>Total Yang Disetujui</td>
	 <td>Disetujui Oleh</td>
     <td>Status</td>
	 <td colspan="4">&nbsp;</td>
	</tr>
	<?
	 // query data
	 if(empty($HTTP_GET_VARS['filter'])){
//		 $sql	= mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY id_restitusi) AS No, *, CONVERT(CHAR(12), tanggal, 103) TGL, jml_diajukan, jml_disetujui FROM MedicalRestitusiDetail WHERE NIK = '$nik' ",$conn);

		 $sql	= mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY tanggal DESC) AS No, CONVERT(CHAR(12), tanggal, 103) TGL,nomor,Periode FROM MedicalRestitusiDetail WHERE NIK = '$nik' AND Periode='".date("Y")."' GROUP BY nomor, tanggal, Periode",$conn);
	 }
	 else{
		 //$sql	= mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY id_restitusi) AS No, *, CONVERT(CHAR(12), tanggal, 103) TGL, jml_diajukan, jml_disetujui FROM MedicalRestitusiDetail WHERE NIK = '$nik' AND Periode='".$HTTP_GET_VARS['filter']."' GROUP BY nomor",$conn);
		 $sql	= mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY tanggal DESC) AS No, CONVERT(CHAR(12), tanggal, 103) TGL,nomor,Periode FROM MedicalRestitusiDetail WHERE NIK = '$nik' AND Periode='".$HTTP_GET_VARS['filter']."' GROUP BY nomor, tanggal, Periode",$conn);
	 }
	 while($row	= mssql_fetch_array($sql)){
	 	echo"
		 <tr class='contentlist'>
		  <td align=right>$row[No]</a></td>
		  <td>$row[nomor]</a></td>
		  <td align=right>$row[TGL]</a></td>
		  <td align=right>$row[Periode]</a></td>";
		  // get total jumlah yang diajukan
		  $sqlaju = mssql_query("SELECT SUM(jml_diajukan) total_diajukan,SUM(jml_disetujui) total_disetujui,NIK,status,DiperiksaBy, mata_anggaran FROM MedicalRestitusiDetail WHERE NIK='$nik' AND nomor='$row[nomor]' GROUP BY NIK,status,DiperiksaBy,mata_anggaran",$conn);
		  $rowaju = mssql_fetch_array($sqlaju);
		  /*
			// RAWAT JALAN
			$MA 	= " AND mata_anggaran IN ('811101','811103','811199') ";
			$jenis 	= "RJ";
			CallMedical($conn,$awal,$akhir,$MA,$nik,$jenis);
			// RAWAT INAP
			$MA 	= " AND mata_anggaran IN ('811102','811106') ";
			$jenis 	= "RI";
			CallMedical($conn,$awal,$akhir,$MA,$nik,$jenis);
			// KACAMATA
			$MA 	= " AND mata_anggaran IN ('811104') ";
		  */
		  echo"<td>";
		  switch($rowaju[mata_anggaran]){
		  	case "811101";
				echo"Rawat Jalan";
				break;
		  	case "811103";
				echo"Rawat Jalan";
				break;
		  	case "811199";
				echo"Rawat Jalan";
				break;
		  	case "811102";
				echo"Rawat Inap";
				break;
		  	case "811106";
				echo"Rawat Inap";
				break;
		  	case "811104";
				echo"Kacamata";
				break;
		  }
		  echo"</td>
		  <td align=right>Rp.".number_format($rowaju[total_diajukan])."</a></td>
		  <td align=right>Rp.".number_format($rowaju[total_disetujui])."</a></td>
		  <td align=right>$rowaju[DiperiksaBy]</a></td>
		  <td>";
			if($rowaju[status] == NULL || $rowaju[status] == "A"){
				echo"Disetujui";
			}
			
			if($rowaju[status] == "P"){
				echo"<span style='color:red;'>Sedang diproses ...</span>";
			}			
		echo"</td>
	  	  <td><a href='../report/rep_medical.php?nik=$rowaju[NIK]&amp;no_res=$row[nomor]&amp;periode=$row[Periode]' target='_blank'><img src='../images/fileprint.png' title='Cetak' alt='Cetak' border=0></a></td>
		  <td>";
		  // approval
		  if($rpar[approval] == 1){
		  echo"
		  <a href='../form/frm_emp_medical.php?nikg=$rowaju[NIK]&amp;no_res=$row[nomor]&amp;st=setuju'><img src='../images/apply.png' title='Persetujuan' alt='Persetujuan' border=0></a>";
		  }
		  echo"</td>
	  	  <td>";
		  //edit
		  if($rpar[edit] == 1){
		  echo"<a href='../form/frm_emp_medical.php?nikg=$rowaju[NIK]&amp;no_res=$row[nomor]&amp;op=edit'><img src='../images/b_edit.png' title='Edit' alt='Edit' border=0></a>";
		  }
		  echo"</td>
	      <td>";
		  //hapus
		  if($rpar[hapus] == 1){
		  echo"<a href='#' onclick='hapus(\"medical\",\"$rowaju[NIK]\",\"$row[nomor]\")'><img src='../images/b_delete.png' title='Delete' alt='Delete' border='0'></a>";
		  }
		  echo"</td>
		 </tr>
		";
	 }
	?>
   </table>
   </fieldset>
  </td>
 </tr>
 <?
 	// tambah
 	if($rpar[tambah] == 1){
 ?>
 <?
 	// end hak akses
	}
 }
 elseif($show == "detail")
 {
 ?>

 <? 
 }
 // SETUP DATA MEDICAL
 elseif($show == "setup_medical"){
 $sNama = mssql_query("SELECT * FROM Karyawan WHERE NIK='$nik'",$conn);
 $rNama = mssql_fetch_array($sNama);
 // untuk hak akses
 $spar = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='setup_medical'",$conn);
 $rpar = mssql_fetch_array($spar);	

 ?>
 <tr>
 <td>
  <table width="100%" style="position:relative; left:12px;" cellpadding="0">
   <tr>
	<td class="line_bottom" colspan="2">
    <table width="100%">
     <tr>
      <td><b>DATA PLAFON PENGOBATAN KARYAWAN</b> | <a href="listmedical.php?show=historical&nik=<?=$nik?>">DATA PENGAJUAN PENGOBATAN</a></td>
     </tr>
    </table>
    </td>
   </tr>
  </table>
 </td>
 </tr>
 <tr>
 <td>
 <table width="100%" style="position:relative; left:12px;">
 <tr>
  <td>
  <table>
   <tr> 
    <td width="150">NIK</td>
	<td><input type="text" name="nik" value="<?=$rNama[NIK]?>" readonly="" /></td>
   </tr>
   <tr> 
    <td>Nama</td>
	<td><input type="text" name="nama" size="50" value="<?=$rNama[Nama]?>" readonly="" /></td>
   </tr>
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#CCCCCC" /></td>
 </tr>
<tr>
 <td width="100%" valign="top">
 <fieldset><legend>Data Keluarga</legend>
  <table border="0" cellpadding="3" cellspacing="1" width="100%">
    <tr class="headlist">
	 <td>No.</td>
	 <td>Nama</td>
	 <td>Hubungan</td>
	 <td>Jenis Kelamin</td>
	 <td>Tempat, Tanggal Lahir</td>
	 <td>Pendidikan</td>
	 <td>Pekerjaan</td>
	 <td>Alamat</td>
	</tr>
<?
// data keluarga
	$resKel	= mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Hubungan) as No, NIK, Remarks, C.nama Pendidikan, Nm_Keluarga, JKel, A.TempatLahir, CONVERT(CHAR(21), Tgl_Lahir, 103) tgl_lahir, Pekerjaan, Alamat FROM Keluarga A, MstData B, VPendidikan C WHERE NIK='$nik' AND B.GroupCode='hubungankeluarga' AND B.Code=A.Hubungan AND A.TingkatPendidikan=C.kode AND IsTertanggung='1') SELECT * FROM limit ORDER BY No",$conn);
	$SqlKelCnt = mssql_num_rows($resKel);
	if($SqlKelCnt > 0){
		while($rowKel	= mssql_fetch_array($resKel)){
		echo"
		 <tr class=contentlist valign=top>
		  <td align=right>$rowKel[No]</td>
		  <td>$rowKel[Nm_Keluarga]</td>
		  <td>$rowKel[Remarks]</td>
		  <td>";
		if($rowKel[JKel] == "0"){
			echo"Pria";
		}
		elseif($rowKel[JKel] == "1"){
			echo"Wanita";
		}  
		echo"</td><td>$rowKel[TempatLahir], $rowKel[tgl_lahir]</td>
		  <td>$rowKel[Pendidikan]</td>
		  <td>$rowKel[Pekerjaan]</td>
		  <td>$rowKel[Alamat]</td>
		 </tr>
		";
		} 
	}
	else{
		echo"<tr class=cell><td align=center colspan=20>--- TIDAK ADA DATA ---</td></tr>";
	}
?>
  </table>
  </fieldset>
 </td>
</tr>
<tr>
 <td>
  <fieldset>
  <legend>History Plafon Awal</legend>
  <table width="60%">
   <tr class="headlist">
    <td width="15">No.</td>
	<td width="50">Periode</td>
	<td width="100">Tanggal Setting</td>
	<td width="200">Plafon Rawat Jalan</td>
    <td width="200">Plafon Rawat Inap</td>    
	<td width="200">Plafon Kaca Mata</td>
	<td colspan="2">&nbsp;</td>
   </tr>
   <?
   	$splafon = mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, CONVERT(CHAR(12), DateSetup, 103) tanggal, * FROM MedicalSetupAwal WHERE NIK='$nik' ORDER BY Periode, DateSetup",$conn);
	while($rplafon = mssql_fetch_array($splafon)){
	 echo"
	 <tr class='contentlist'>
	  <td align='right'>$rplafon[No]</td>
	  <td align='right'>$rplafon[Periode]</td>
	  <td align='right'>$rplafon[tanggal]</td>
	  <td align='right'>Rp.".number_format($rplafon[PlafonRawatJalan])."</td>
	  <td align='right'>Rp.".number_format($rplafon[PlafonRawatInap])."</td>
	  <td align='right'>Rp.".number_format($rplafon[PlafonKacaMata])."</td>
	  <td>";
	  // edit
	  if($rpar[edit] == 1){
	  echo"<a href='../form/frm_emp_plafon.php?show=plafon_awal&amp;nik=$rplafon[NIK]&amp;no=$rplafon[No]&amp;op=edit'><img src='../images/b_edit.png' title='Edit' alt='Edit' border=0></a>";
	  }
	  echo"</td>
	  <td>";
	  // hapus
	  if($rpar[hapus] == 1){
	  echo"<a href='#' onclick='hapus(\"plafon_awal\",\"$rplafon[NIK]\",\"$rplafon[No]\")'><img src='../images/b_delete.png' title='Delete' alt='Delete' border='0'></a>";
	  }
	  echo"</td>
	 </tr>
	 ";
	}
   ?>
  </table><br>
  <?
  	// tambah
  	if($rpar[tambah] == 1){
  ?>
  <input type="button" value="Tambah" class="button" onclick="Javascript:location.href='../form/frm_emp_plafon.php?show=plafon_awal&amp;nik=<?=$rNama[NIK]?>&amp;nama=<?=$rNama[Nama]?>'">
  <?
  }
  ?>
  </fieldset>
 </td>
</tr>
<tr>
 <td>
  <fieldset>
  <legend>Setting No. Rekening</legend>
  <table width="70%">
   <tr class="headlist">
    <td width="15">No.</td>
	<td width="150">No. Rekening</td>
	<td>Atas Nama</td>
	<td>Nama Bank</td>
   </tr>
   <?
   	$sBank = mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM MedicalNoRekening A, MstBank B WHERE A.IdBank=B.IdBank AND NIK='$nik'",$conn);
	while($rBank = mssql_fetch_array($sBank)){
		echo"
		 <tr class=contentlist>
		  <td align=right>$rBank[No]</td>
		  <td align=right>$rBank[no_rek]</td>
		  <td>$rBank[nama_rek]</td>
		  <td>$rBank[NamaBank]</td>
		 </tr>
		";
	}
   ?>
  </table><br>
  <?
  	// tambah
  	if($rpar[tambah] == 1){
  ?>
  <input type="button" value="Edit" class="button" onclick="Javascript:location.href='../form/frm_emp_plafon.php?show=rekening&amp;nik=<?=$rNama[NIK]?>&amp;nama=<?=$rNama[Nama]?>'" >
  <?
  }
  ?>
  </fieldset>
 </td>
</tr>
</table>
</td>
</tr>
 <?
 }
 ?>
</table>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>